//
//  LXHotAuthorCell.m
//  喜马拉雅改良版框架
//
//  Created by liuxin on 15/12/29.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "LXHotAuthorCell.h"

@implementation LXHotAuthorCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
-(void)setIndex:(NSInteger)index{
    self.indexTemp = index;
    self.num.text = [NSString stringWithFormat:@"%ld",index+1];
}
-(void)createSubViews{
    self.num = [[UILabel alloc]init];
    self.num.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.num];
    [self.num mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(25);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
    }];
    
    self.userImage = [[UIImageView alloc]init];
    [self.contentView addSubview:self.userImage];
    [self.userImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(60);
        make.width.mas_equalTo(60);
        make.left.equalTo(self.num.mas_right).offset(5);
    }];
    
    self.titleLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userImage.mas_right).offset(10);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(20);
        make.top.mas_equalTo(10);
    }];
    
    self.authorLabel = [[UILabel alloc]init];
    self.authorLabel.textColor = [UIColor lightGrayColor];
    self.authorLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.authorLabel];
    [self.authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(5);
        make.right.mas_equalTo(-15);
        make.left.equalTo(self.userImage.mas_right).offset(10);
        make.height.equalTo(@15);
    }];
    UIImageView  *trackImage = [[UIImageView alloc]init];
    trackImage.image = [UIImage imageNamed:@"user_fans@2x.png"];
    [self.contentView addSubview:trackImage];
    [trackImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.authorLabel.mas_bottom).offset(5);
        make.left.equalTo(self.authorLabel);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(15);
    }];
    self.tracksLabel = [[UILabel alloc]init];
    self.tracksLabel.textColor = [UIColor lightGrayColor];
    self.tracksLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.tracksLabel];
    [self.tracksLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.authorLabel.mas_bottom).offset(5);
        make.left.equalTo(trackImage.mas_right).offset(5);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(15);
    }];
}
-(void)setCellModel:(LXHotAuthorModel *)cellModel{
    if (self.indexTemp == 0) {
        self.num.textColor = [UIColor colorWithRed:1.000 green:0.241 blue:0.157 alpha:1.000];
    }else if(self.indexTemp == 1){
        self.num.textColor = [UIColor colorWithRed:1.000 green:0.595 blue:0.145 alpha:1.000];
    }else if(self.indexTemp ==2){
        self.num.textColor = [UIColor colorWithRed:0.380 green:1.000 blue:0.326 alpha:1.000];
    }else{
        self.num.textColor = [UIColor blackColor];
    }
    [self.userImage sd_setImageWithURL:[NSURL URLWithString:cellModel.largeLogo] placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
//    self.titleLabel.text = cellModel.nickname;
    NSTextAttachment *textAttachment01 = [[NSTextAttachment alloc] init];
    textAttachment01.image = [UIImage imageNamed: @"me_fans_verifylogo@2x.png"];  //设置图片源
    textAttachment01.bounds = CGRectMake(0, -2, 15, 15);          //设置图片位置和大小
    NSMutableAttributedString *attrStr01 = [[NSMutableAttributedString alloc] initWithString: cellModel.nickname];
    
    [attrStr01 addAttribute: NSFontAttributeName value: [UIFont systemFontOfSize: 17] range: NSMakeRange(0, cellModel.nickname.length)];
    NSAttributedString *attrStr11 = [NSAttributedString attributedStringWithAttachment: textAttachment01];
    
    [attrStr01 insertAttributedString: attrStr11 atIndex: cellModel.nickname.length];  //NSTextAttachment占用一个字符长度，插入后原字符串长度增加1
    
    self.titleLabel.attributedText = attrStr01;
    self.authorLabel.text = cellModel.personDescribe;
    if (cellModel.followersCounts >10000) {
        self.tracksLabel.text = [NSString stringWithFormat:@"%.1f万",cellModel.followersCounts/10000.0];
    }else{
    self.tracksLabel.text = [NSString stringWithFormat:@"%ld",cellModel.followersCounts];
    }
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
